﻿using System.Data;

namespace MyWeb.Datamining.Kmeans
{
    public class ConvertDataTable
    {
        public DataTable DataTableStatistics(DataTable dUserId, DataTable dDistributionId, DataTable dViewNumber,DataTable dt)
        {
            DataTable dStatistics = new DataTable();

            dStatistics.Columns.Add("User_Id", typeof(string));
            for (int i = 0; i < dDistributionId.Rows.Count; i++)
            {
                dStatistics.Columns.Add("View" + i, typeof(string));
            }
            for (int i = 0; i < dUserId.Rows.Count; i++)
            {
                DataRow rows = dStatistics.NewRow();
                rows["User_Id"] = dUserId.Rows[i]["User_Id"].ToString();
                int m = i * (dt.Rows.Count);
                int n = dDistributionId.Rows.Count;
                for (int j = 0; j < n; j++)
                {
                    rows["View" + j] = dViewNumber.Rows[(i+1)*n-(n-j)]["ViewNumber"].ToString();
                }
                dStatistics.Rows.Add(rows);
            }
            
            return dStatistics;
        }
    }
}